
<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once APPLICATION_PATH.'\misc\sessionController.php';
class Application_Controllers_Admin_ActionLoginController
{   public $wrongMessage;

    public function preLogin($form){
        $admin =  new Application_Model_DbTable_Admin();
        $username=$form->getValue('username');
        $password=$form->getValue('password');
        $this->wrongMessage="";
        if($admin->checkLogin($username, $password)){
            return true;
        }else{
            $this->wrongMessage="wrong username or password";
            return false;
        }
    }
    public function onLogin($form){
        $sessionController = new sessionController();
        $admin = new Application_Model_DbTable_Admin();
        $log = new Application_Model_DbTable_Log();
        $role = new Application_Model_DbTable_Role();
        $action = new Application_Model_DbTable_Action();
        $actionLog = new Application_Model_DbTable_Actionlog();
        //add log into database
        //getAdminData
        $row=$admin->getAdminId($form->getValue('username'));
        $log->addLoginLog($row['admin_id']);
        $logId = $log->getLastLog($row['admin_id']);
        //setting session
       //set the session for 30 minutes
       $actionLog->addActionLog($logId,
                    "[".$_SERVER['REMOTE_ADDR']."]".
                     "[Super Admin] Log In");
       //setting session param

       $params = array(
                'nameSpace'=>'superadmin',
                'roleId'=>$row['role_id'],
                'role'=>$role->getRoleName($row['role_id']),
                'username'=>$form->getValue('username'),
                'id'=>$row['admin_id'],
                'logId'=>$logId          
       );
      $sessionController->initialize($params);
    }
}
?>
